package com.bnz.starter.config;

import com.bnz.starter.properties.HelloProperties;
import com.bnz.starter.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(HelloProperties.class)
@ConditionalOnClass(HelloService.class)         // 当前系统中是否有HelloService这个类，这个是一个条件注解
public class HelloServiceAutoConfiguration {


    @Bean
    public HelloService helloService(HelloProperties helloProperties){

        HelloService helloService=new HelloService();
        helloService.setAge(helloProperties.getAge());
        helloService.setName(helloProperties.getName());

        return helloService;
    }

}
